﻿using BlogDemo.Core.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Text;

namespace BlogDemo.Infrastructure.Database.EntityTypeConfigurations
{
    public class PostConfig
        : IEntityTypeConfiguration<Post>
    {
        public void Configure(EntityTypeBuilder<Post> builder)
        {
            //Table.
            builder.ToTable("Post");
            //Key.
            builder.HasKey(t=>t.Id);
            //Props.
            builder.Property(t => t.Id)
                .HasColumnName("Id")
                .IsRequired(true);
            builder.Property(t => t.Title)
                .HasColumnName("Title")
                .HasMaxLength(20)
                .IsUnicode(true)
                .IsRequired(true);
            builder.Property(t => t.Body)
                .HasColumnName("Body")
                .HasMaxLength(-1)
                .IsUnicode(true)
                .IsRequired(true);
            builder.Property(t => t.Author)
                .HasColumnName("Author")
                .HasMaxLength(10)
                .IsUnicode(true)
                .IsRequired(true);
            builder.Property(t => t.LastModifyTime)
                .HasColumnName("LastModifyTime")
                .HasDefaultValue(DateTime.Now)
                .IsRequired(true);
        }
    }
}
